﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
//
using PerceptiveMCAPI;
//
namespace PerceptiveMCAPI_Test
{
   public partial class get_listUnsubscribe : System.Web.UI.UserControl
   {

      public ApiMethod method { get; set; }

      public string listId
      {
         get { return tbListId.Text.Trim(); }
         set { tbListId.Text = value; }
      }
      public string email_address                  // for listUnsubscribe
      {
         get { return tbEmails.Text.Trim(); }
         set { tbEmails.Text = value; }
      }
      public List<string> emailList                // for listBatchUnsubscribe
      {
         get { return GetEmailList(); }
      }
      public bool delete_member
      {
         get { return cbDeleteMbr.Checked; }
         set { cbDeleteMbr.Checked = value; }
      }
      public bool send_goodbye
      {
         get { return cbSendGoodbye.Checked; }
         set { cbSendGoodbye.Checked = value; }
      }
      public bool send_notify
      {
         get { return cbSendNotify.Checked; }
         set { cbSendNotify.Checked = value; }
      }

      public bool Setup()
      {
         this.Visible = true;
         lblSection.Text = method.section;
         lblMethod.Text = method.name;
         //
         tbEmails.Text = "";
         delete_member = MCAPISettings.default_listUnsubscribe_delete_member;
         send_goodbye = MCAPISettings.default_listUnsubscribe_send_goodbye;
         send_notify = MCAPISettings.default_listUnsubscribe_send_notify;

         if ( method.name == "listBatchUnsubscribe" )
         {
            litBatchNote.Visible = true;
            tbEmails.TextMode = TextBoxMode.MultiLine;
         }
         else
         {
            litBatchNote.Visible = false;
            tbEmails.TextMode = TextBoxMode.SingleLine;
         }
         return true;
      }

      private List<string> GetEmailList()
      {
         List<string> emails = new List<string>();

         string temp = tbEmails.Text.Trim();
         if ( !string.IsNullOrEmpty( temp ) )
         {
            string[] seps = { ",", ";", "|", " " };
            string[] emailSplit = temp.Split( seps, StringSplitOptions.RemoveEmptyEntries );
            foreach ( string email in emailSplit ) { emails.Add( email ); }
         }
         return emails;
      }
   }
}